# from rest_framework import serializers
# from userAccount import models
from rest_framework import serializers
from dbs_insert import models
from public.tools import check_database


class TopicDetailSerializer(serializers.ModelSerializer):
    class Meta:
            model = models.DfeTopic
            fields = "__all__"


class DatabaseSerializer(serializers.Serializer):
    project_id = serializers.IntegerField(required=True)
    db_type = serializers.CharField(max_length=20,required=True)
    creator_id = serializers.IntegerField(required=True)

    def is_valid(self, raise_exception=False):
        result = super(DatabaseSerializer, self).is_valid()
        database_check = False
        assert check_database(self.data["project_id"],self.data["db_type"])
        return result


class TableSerializer(serializers.Serializer):
    project_id = serializers.IntegerField(required=True)
    db_type = serializers.CharField(max_length=20, required=True)
    db_name = serializers.CharField(max_length=50, required=True)
    topic_name = serializers.CharField(max_length=50, required=True)
    table_name = serializers.CharField(max_length=20,required=True)
# class UserSerializer(serializers.Serializer):
#         nickname = serializers.CharField(required=True, allow_blank=True, max_length=100)
#         phone = serializers.CharField(max_length=11,required=True)
#         password = serializers.CharField(required=True,max_length=100)
#         code = serializers.CharField(required=True)
#
#         def is_valid(self, raise_exception=False):
#             result = super(UserSerializer, self).is_valid()
#             phone_check = False
#             password_check = False
#             account_check = False
#             # email_check = False
#
#             # assert check_email(self.data["email"])
#             return result
#         # model = models.TUserInfo
#         # fields = ("f_nickname","f_mobile_phone","password")
#         # fields = "__all__"
#
#
# class UserDetailSerializer(serializers.ModelSerializer):
#     # f_nickname = serializers.CharField(required=True, allow_blank=True, max_length=100,label='用户昵称')
#     # f_mobile_phone = serializers.CharField(max_length=11, required=True,label="用户手机号")
#     # f_passwd = serializers.CharField(required=True, max_length=100,label="用户密码")
#
#     class Meta:
#             model = models.TUserInfo
#             fields = "__all__"
#
#
# class LoginSerializer(serializers.Serializer):
#
#     # model = models.TUserInfo
#     # fields = ("f_mobile_phone","password")
#     # fields = "__all__"
#     phone = serializers.CharField(max_length=11, required=True)
#     password = serializers.CharField(required=True, max_length=100)
#
#
# class CompanyDataSerializer(serializers.ModelSerializer):
#
#     class Meta:
#             model = models.TEnterpriseData
#             fields = "__all__"
#
#
# class CheckSerializer(serializers.Serializer):
#     account = serializers.CharField(max_length=20, required=True)
#
#     def is_valid(self, raise_exception=False):
#         result = super(CheckSerializer, self).is_valid()
#         phone_check = False
#         assert check_mobile(self.data["account"])
#         return result
#
#
# class BatchAccountSerializer(serializers.Serializer):
#     num = serializers.CharField(required=True)
#     nickname = serializers.CharField(required=True)
#     password = serializers.CharField(required=True)